<?php
	require_once 'php-sdk/facebook.php';
	require_once 'php-sdk/base_facebook.php';
	require_once 'gameAPI.php';

	$user_id = get_user_id();

	$factory_id = get_factory_id($user_id);
	
	$supervisors = get_certain_workers($factory_id, 'Supervisor');
	$office_workers = get_certain_workers($factory_id, 'Office worker');
	$production_workers = get_certain_workers($factory_id, 'Production line worker');
	/*
	$supervisor_item_ids = get_certain_items($factory_id, 1);
	$office_worker_item_ids = get_certain_items($factory_id, 3);
	$production_worker_item_ids = get_certain_items($factory_id, 2);
	
	$supervisor_item_quantity = get_certain_item_quantity($factory_id, 1);
	$office_worker_item_quantity = get_certain_item_quantity($factory_id, 3);
	$production_worker_item_quantity = get_certain_item_quantity($factory_id, 2);
	*/
	$supervisor_small_item_quantity = get_item_quantity_by_id($factory_id, 1);
	$office_worker_small_item_quantity = get_item_quantity_by_id($factory_id, 3);
	$production_worker_small_item_quantity = get_item_quantity_by_id($factory_id, 5);
	
	$supervisor_normal_item_quantity = get_item_quantity_by_id($factory_id, 2);
	$office_worker_normal_item_quantity = get_item_quantity_by_id($factory_id, 4);
	$production_worker_normal_item_quantity = get_item_quantity_by_id($factory_id, 6);
	
	$credit = get_credit($user_id);
	
	$user_ids = implode(',', get_all_user_ids());
?>

<html>
<head>

<title>Factory Screen</title>
	
	<style type="text/css">
		#canvas {
			height:780px;
			width:745px;
			left:0px;
			top:0px;
			background-image:url(images/Factory/factory_page.jpg);
			background-repeat:no-repeat;
			position:absolute;
		}
				
		#UpgradeButton {
			height:40px;
			width:140px;
			top:30px;
			left:27px;
			position:absolute;
		}
		#HireButton {
			height:40px;
			width:140px;
			top:30px;
			right:33px;
			position:absolute;
		}
		#FrenFactoryButton {
			height:50px;
			width:280px;
			top:20px;
			left:220px;
			position:absolute;
		}
		#InviteButton {
			height:40px;
			width:140px;
			top:30px;
			left:32px;
			position:absolute;
		}
		#CashText {
			height:40px;
			width:140px;
			top:35px;
			right:20px;
			text-align:left;
			vertical-align:bottom;
			font-size:40px;
			font-family:"Lucida Console","Courier", serif;
			color:#8A5A3D;
			position:absolute;
		}
		
		#TopBar {
			height:100px;
			width:725px;
			top:10px;
			left:10px;
			position:absolute;
		}

		#DaBoss {
			height:180px;
			width:725px;
			top:120px;
			left:10px;
			position:absolute;
		}
		#OfficeWorker {
			height:180px;
			width:725px;
			top:311px;
			left:9px;
			position:absolute;
		}
		#ProductionWorker {
			height:180px;
			width:725px;
			top:497px;
			left:9px;
			position:absolute;
		}
		
		#BottomBar {
			height:100px;
			width:725px;
			top:674px;
			left:9px;
			position:absolute;
		}
		
		.ProfilePhotos {
			right:25px;
			top:17px;
			position:absolute;
		}
		.NormalItemSlot {
			left:117px;
			top:96px;
			height:70px;
			position:absolute;
			width: 309px;
		}
		.SmallItemSlot {
			left:52px;
			top:55px;
			height:30px;
			width:150px;
			position:absolute;
		}
		
		#LikeBar {
			left:300px;
			top:82px;
			height:16px;
			width:150px;
			position:absolute;
		}
		#LikeButton {
			left:20px;
			top:0px;;
			with:745px;
			height:50px;
			position:absolute;
		}
		#FrenFactoryIcon {
			left:0px;
			top:0px;
			width:16px;
			height:16px;
			position:absolute;
		}
	</style>

	<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25431105-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script> 

	<script type="text/javascript">
		
		var user_ids = [<?php echo $user_ids; ?>];
		
		function Invite()
		{
			window.fbAsyncInit = function() {
   				FB.init({
      				appId  : '271211432894561',
     				status : true, // check login status
    				cookie : true, // enable cookies to allow the server to access the session
  		    		xfbml  : true  // parse XFBML
  				});
	
				FB.ui({method: 'apprequests', 
					message: "FrenFactory is sooo much fun! Come and try it out!", 
					data: 'tracking information for the user',
					exclude_ids: user_ids
				});
  			};

  			(function() {
    			var e = document.createElement('script');
    			e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
   				e.async = true;
    			document.getElementById('fb-root').appendChild(e);
  			}());

		}
	</script>
	
</head>

<body>
	<div id="canvas">
		<div id="TopBar">
			<div>
				<img id="UpgradeButton" src="images/Factory/UPGRADE.png" 
					onmouseover="this.src='images/Factory/UPGRADE_over.png';"
					onmousedown="this.src='images/Factory/UPGRADE_click.png'; window.location.href='buy.php';"
					onmouseout="this.src='images/Factory/UPGRADE.png';"
					onmouseup="this.src='images/Factory/UPGRADE_over.png';"
				/>
			</div>
			<div><img id="FrenFactoryButton" src="images/Factory/FrenFactory title.png"
					onmouseover="this.src='images/Factory/FrenFactory title_over.png';"
					onmousedown="this.src='images/Factory/FrenFactory title_click.png'; window.location.href='http://www.facebook.com/apps/application.php?id=271211432894561';"
					onmouseout="this.src='images/Factory/FrenFactory title.png';"
					onmouseup="this.src='images/Factory/FrenFactory title_over.png';"
				/>
			</div>
			<div>
				<img id="HireButton" src="images/Factory/STATUS.png" 
					onmouseover="this.src='images/Factory/STATUS_over.png';"
					onmousedown="this.src='images/Factory/STATUS_click.png'; window.location.href='play.php';"
					onmouseout="this.src='images/Factory/STATUS.png';"
					onmouseup="this.src='images/Factory/STATUS_over.png';"
				/>
			</div>
	  </div>
		<div id="DaBoss">
			<div class="ProfilePhotos">
				<table>
					<tr>
						<?php foreach($supervisors as $supervisor) : ?>
						<td>
							<?php if ($supervisor == -1): ?>
								<img src="http://107.20.229.155/sqwtest/images/blank_profile_picture_small.jpg">
							<?php else: ?>
								<img src="https://graph.facebook.com/<?php echo $supervisor ?>/picture" />
							<?php endif ?>
						</td>
						<?php endforeach; ?>
					</tr>
				</table>
		 	</div>
		  	<div class="SmallItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $supervisor_small_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/Big Deal_icon_mini.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
		  </div>				
			<div class="NormalItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $supervisor_normal_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/Golf Set_icon.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
			</div>
	  </div>
		<div id="OfficeWorker">
			<div class="ProfilePhotos">
				<table>
					<tr>
						<?php foreach($office_workers as $office_worker) : ?>
						<td>
							<?php if ($office_worker == -1): ?>
								<img src="http://107.20.229.155/sqwtest/images/blank_profile_picture_small.jpg">
							<?php else: ?>
								<img src="https://graph.facebook.com/<?php echo $office_worker ?>/picture" />
							<?php endif ?>
						</td>
						<?php endforeach; ?>
					</tr>
				</table>
		  </div>
			<div class="SmallItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $office_worker_small_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/A.C.C.A Training_icon_mini.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
			</div>
			<div class="NormalItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $office_worker_normal_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/Cabinet_icon.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
			</div>
	  </div>
		<div id="ProductionWorker">
			<div class="ProfilePhotos">
				<table>
					<tr>
						<?php foreach($production_workers as $production_worker) : ?>
						<td>
							<?php if ($production_worker == -1): ?>
								<img src="http://107.20.229.155/sqwtest/images/blank_profile_picture_small.jpg">
							<?php else: ?>
								<img src="https://graph.facebook.com/<?php echo $production_worker ?>/picture" />
							<?php endif ?>
						</td>
						<?php endforeach; ?>
					</tr>
				</table>
			</div>
			<div class="SmallItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $production_worker_small_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/A.C.T.A Training_icon_mini.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
			</div>
			<div class="NormalItemSlot">
				<table>
					<tr>
						<?php for ($i = 0; $i < $production_worker_normal_item_quantity; $i++) : ?>
						<td>
							<img src="images/Upgrade/Toolbox_icon.png" />
						</td>
						<?php endfor ?>
					</tr>
				</table>
			</div>
	  </div>
		<div id="BottomBar">
			<div><img id="InviteButton" src="images/Factory/INVITE.png" 
					onMouseOver="this.src='images/Factory/INVITE_over.png';"
					onMouseDown="this.src='images/Factory/INVITE_click.png'; Invite();"
					onMouseOut="this.src='images/Factory/INVITE.png';"
					onMouseUp="this.src='images/Factory/INVITE_over.png';"
				/></div>
			<div id="CashText"><?php echo $credit; ?></div>
		</div>
	</div>
<div id="LikeBar">
		<img id="FrenFactoryIcon" src="images/SmallIcon.jpg" />
		<div id="LikeButton">
			<iframe src="http://www.facebook.com/plugins/like.php?app_id=169869689753765&amp;href=www.facebook.com%2Fapps%2Fapplication.php%3Fid%3D271211432894561&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></div>
		</div>
</body>
</html> 
